package actions;

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.StudentDBModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import data.*;

public class DegreeLocationAction extends Action {

	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	{
		StudentData studentData = (StudentData) request.getSession().getAttribute("studentData");
		
		Degree currentDegree = new Degree();
		StudentDBModel db = new StudentDBModel();
		
		currentDegree.setLocation((String) request.getParameter("degreeCountry"));
		if(request.getParameter("stateID") != null)
		{
			currentDegree.setLocationID(request.getParameter("stateID"));
		}
		else if(request.getParameter("countryID") != null)
		{
			currentDegree.setLocationID(request.getParameter("countryID"));
		}
		
		RowSet crsUnis = db.getUniversitiesByLocation(currentDegree.getLocation());
		request.setAttribute("crsUnis", crsUnis);
		
		Vector<String> formData = studentData.getFormData();
		formData.add("Degree Obtained In: "+currentDegree.getLocation());
		
		request.getSession().setAttribute("formData", formData);
		request.getSession().setAttribute("studentData", studentData);	
		request.getSession().setAttribute("currentDegree", currentDegree);
		
		return mapping.findForward("success");
	}
}
